package com.ruoyi.project.module.itemDetail.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.constant.BusinessType;
import com.ruoyi.project.module.itemDetail.domain.ItemDetail;
import com.ruoyi.project.module.itemDetail.service.IItemDetailService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;

/**
 * 商品库存 信息操作处理
 * 
 * @author ruoyi
 * @date 2018-08-08
 */
@Controller
@RequestMapping("/module/itemDetail")
public class ItemDetailController extends BaseController
{
    private String prefix = "module/itemDetail";
	
	@Autowired
	private IItemDetailService itemDetailService;
	
	@RequiresPermissions("module:itemDetail:view")
	@GetMapping()
	public String itemDetail()
	{
	    return prefix + "/itemDetail";
	}
	
	/**
	 * 查询商品库存列表
	 */
	@RequiresPermissions("module:itemDetail:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(ItemDetail itemDetail)
	{
		startPage();
        List<ItemDetail> list = itemDetailService.selectItemDetailList(itemDetail);
		return getDataTable(list);
	}
	
	/**
	 * 新增商品库存
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存商品库存
	 */
	@RequiresPermissions("module:itemDetail:add")
	@Log(title = "商品库存", action = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(ItemDetail itemDetail)
	{		
		return toAjax(itemDetailService.insertItemDetail(itemDetail));
	}

	/**
	 * 修改商品库存
	 */
	@GetMapping("/edit/{itemDetailId}")
	public String edit(@PathVariable("itemDetailId") Integer itemDetailId, ModelMap mmap)
	{
		ItemDetail itemDetail = itemDetailService.selectItemDetailById(itemDetailId);
		mmap.put("itemDetail", itemDetail);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存商品库存
	 */
	@RequiresPermissions("module:itemDetail:edit")
	@Log(title = "商品库存", action = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(ItemDetail itemDetail)
	{		
		return toAjax(itemDetailService.updateItemDetail(itemDetail));
	}
	
	/**
	 * 删除商品库存
	 */
	@RequiresPermissions("module:itemDetail:remove")
	@Log(title = "商品库存", action = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(itemDetailService.deleteItemDetailByIds(ids));
	}
	
}
